package com.qf.lanzhou.shop.admin.controller;

import com.qf.lanzhou.shop.admin.service.GoodsManageService;
import com.qf.lanzhou.shop.pojo.entity.Goods;
import com.qf.lanzhou.shop.pojo.qo.GoodsClassficationQo;
import com.qf.lanzhou.shop.pojo.vo.BaseRespVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LEON-HE
 */
@Api(tags = "商品管理接口")
@RestController
@RequestMapping("/goodsManage")
public class GoodsManageController extends BaseController {
    @Autowired
    private GoodsManageService manageService;

    @RequestMapping(value = "/insert", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value = "获取所有大小分类")
    public BaseRespVO getClassfication() {
        GoodsClassficationQo classfication = manageService.getAllClassfication();
        return convertSuccessResult(classfication);
    }

    @RequestMapping(value = "/insertGoodsInfo", method = RequestMethod.POST)
    @ResponseBody
    @ApiOperation(value = "插入商品")
    public BaseRespVO InsertGoods(Goods goods) {
        int i = manageService.insertGoods(goods);
        System.out.println(goods);
        return convertSuccessResult("1");
    }

    @GetMapping("/getAllGoods")
    @ApiOperation(value = "/获取所有商品")
    public BaseRespVO selectAllGoods() {
        List<Goods> goodsList = manageService.selectAllGoods();
        BaseRespVO successResult = convertSuccessResult(goodsList);
        return successResult;
    }

    @PostMapping("/updateEvent")
    @ApiOperation(value = "更新商品活动状态")
    public BaseRespVO updateEventStatus(@RequestParam(name = "status", required = false) int status,
                                        @RequestParam(name = "goodId", required = false) int goodId) {
        //int status = Integer.parseInt(statusParam);
        System.out.println("status:" + status + "goodId:" + goodId);
        int result = manageService.updateEventStatus(status, goodId);
        return convertSuccessResult(result);
    }

    @RequestMapping("/put_on")
    @ResponseBody
    @ApiOperation(value = "商品上架")
    public BaseRespVO putOnGoods(Long id) {
        int result = manageService.goodsPutOn(id);
        return convertSuccessResult(result);
    }

    @RequestMapping("/off_the_self")
    @ResponseBody
    @ApiOperation(value = "商品下架")
    public BaseRespVO offTheGoods(Long id) {
        int result = manageService.offTheGoods(id);
        return convertSuccessResult(result);
    }
    @RequestMapping("/delete_goods")
    @ResponseBody
    @ApiOperation(value = "商品删除")
    public BaseRespVO deleteGoods(Long id){
        int result = manageService.deleteGoods(id);
        return convertSuccessResult(result);
    }
    @RequestMapping("/undate_goods")
    @ResponseBody
    @ApiOperation(value = "商品修改架")
    public BaseRespVO undateGoodsMsg(Goods goods){
        System.out.println("进入商品修改");
        System.out.println(goods);
        int result = manageService.undateGoodsMsg(goods);
       return convertSuccessResult(result);
    }

    @RequestMapping("/updateCurrentPrice")
    @ResponseBody
    @ApiOperation(value = "更新商品活动价")
    public BaseRespVO updateCurrentPrice(@RequestParam(name = "currentPrice", required = false) int currentPrice,
                                         @RequestParam(name = "goodId", required = false) int goodId) {
        int result = manageService.updateCurrentPrice(currentPrice, goodId);
        BaseRespVO baseRespVO = convertSuccessResult(result);
        return baseRespVO;
    }

}
